package service

import (
	"context"

	"Data-API-MCP/backend/internal/domain/entity"
	"Data-API-MCP/backend/internal/domain/repository"
)

// MCPService MCP服务接口
type MCPService struct {
	repo repository.MCPServiceRepository
}

// NewMCPService 创建MCP服务实例
func NewMCPService(repo repository.MCPServiceRepository) *MCPService {
	return &MCPService{
		repo: repo,
	}
}

// CreateService 创建MCP服务
func (s *MCPService) CreateService(ctx context.Context, service *entity.MCPService) error {
	return s.repo.CreateService(ctx, service)
}

// GetServices 获取MCP服务列表
func (s *MCPService) GetServices(ctx context.Context) ([]*entity.MCPService, error) {
	return s.repo.ListServices(ctx)
}

// GetService 获取单个MCP服务
func (s *MCPService) GetService(ctx context.Context, id int64) (*entity.MCPService, error) {
	return s.repo.GetService(ctx, id)
}

// UpdateService 更新MCP服务
func (s *MCPService) UpdateService(ctx context.Context, service *entity.MCPService) error {
	return s.repo.UpdateService(ctx, service)
}

// DeleteService 删除MCP服务
func (s *MCPService) DeleteService(ctx context.Context, id int64) error {
	return s.repo.DeleteService(ctx, id)
}

// GetServiceStatus 获取服务状态
func (s *MCPService) GetServiceStatus(ctx context.Context, id int64) (*entity.ServiceStatus, error) {
	return s.repo.GetServiceStatus(ctx, id)
}

// GetServiceMetrics 获取服务指标
func (s *MCPService) GetServiceMetrics(ctx context.Context, id int64) (*entity.ServiceMetrics, error) {
	return s.repo.GetServiceMetrics(ctx, id)
}

// GetServiceLogs 获取服务日志
func (s *MCPService) GetServiceLogs(ctx context.Context, id int64) ([]*entity.ServiceLog, error) {
	return s.repo.GetServiceLogs(ctx, id)
}

// GetServiceConfig 获取服务配置
func (s *MCPService) GetServiceConfig(ctx context.Context, id int64) (map[string]interface{}, error) {
	return s.repo.GetServiceConfig(ctx, id)
}

// UpdateServiceConfig 更新服务配置
func (s *MCPService) UpdateServiceConfig(ctx context.Context, id int64, config map[string]interface{}) error {
	return s.repo.UpdateServiceConfig(ctx, id, config)
}

// ReloadService 重载服务配置
func (s *MCPService) ReloadService(ctx context.Context, id int64) error {
	return s.repo.ReloadService(ctx, id)
}
